﻿using System;
using System.Collections.Generic;
using System.IO;
using System.Linq;
using System.Text;
using System.Threading.Tasks;
using System.Xml.Serialization;

namespace HGPFramework.LogControl
{
    class FuncLog
    {
        public string ReadFile(string _path)
        {
            string data;
            if (File.Exists(_path))
            {
                using (StreamReader reader = new StreamReader(_path, Encoding.UTF8))
                {
                    data = reader.ReadToEnd();
                    return data;
                }
            }
            else
            {
                FileStream fs = new FileStream(_path, FileMode.CreateNew);
                fs.Dispose();
                return "";
            }
        }

        public void WriteFile(string _path, string _data)
        {
            if (File.Exists(_path))
            {
                using (StreamWriter writer = new StreamWriter(_path, true, Encoding.UTF8))
                    writer.WriteLine(_data);
            }
            else
            {
                FileStream fs = new FileStream(_path, FileMode.Create, FileAccess.Write);
                fs.Dispose();
                using (StreamWriter writer = new StreamWriter(_path, true, Encoding.UTF8))
                    writer.WriteLine(_data);
            }
        }

        public void ClearFile(string _path)
        {
            File.Delete(_path);
            FileStream fs = new FileStream(_path, FileMode.CreateNew);
            fs.Dispose();
        }


    }

}
